var layer
layui.use('layer', function () {
    layer = layer
})

// layui.use('form', function () {
//     var form = layui.form;
//     form.render();
// });

var userId = getCookie("userid")

var search = location.search

var orderId = search.replace("?", "")

aftstart(userId, orderId)

// $(".layui-btn").click(function () {
layui.use(['form', 'jquery', 'layer'], function () {

    var form = layui.form;
    // var $ = layui.$;
    var layer = layui.layer;
    //可局部刷新的元素 select,radio,checkbox
    // form.render();          //刷新全部
    form.render('select');  //刷新select选择框
    form.render('select', 'selectfilter');//刷新layfilter为selectfilter1的select


    layer.msg('对不起！我们会提供更好的服务！')

    form.on('submit(formDemo)', function (data) {

        console.log(data)

        if ($("#downbox option:selected").text() !== "--请选择--") {
            $.ajax({
                url: "http://localhost:8080/user/addUAft",
                data: "orderId=" + orderId + "&aftSaleSolve=未处理" + "&aftRequi=" + $("#downbox option:selected").text(),
                asyne: false,
                dataType: "json",
                type: "get",
                success: function (data) {
                    if (data.code === 0) {
                        setTimeout(function () {
                            layer.msg('2秒后将会跳转回上个页面')
                        }, 2000)
                        layer.msg('提交成功了')
                        setTimeout(function () {
                            window.history.back(-1)
                        }, 4000);
                    } else {
                        layer.msg('提交失败了')
                    }
                }
            })
        } else {
            layer.msg('请选择申请内容')
        }
        return false;
    })
})

function aftstart(userId, orderId) {
    $.ajax({
        url: "http://localhost:8080/user/selectUAftShow",
        data: "userId=" + userId + "&orderId=" + orderId,
        asyne: false,
        dataType: "json",
        type: "get",
        success: function (data) {
            if (data.code === 0) {
                aftshow(data)
            }
        }
    })
}

function aftshow(data) {
    let list = data.data
    $("#goodName").val(list.goodName)
    $("#orderNo").val(list.orderNo)
    $("#ordState").val(list.orderState)
    $("#ordCount").val(list.orderCount)
    $("#ordMoney").val(list.orderMoney)
    $("#address").val(list.reserve2)
    $("#goodSize").val(list.reserve3)
}


